package com.tang.lts.core.runner;

import com.tang.lts.core.factory.NameThreadFactory;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Tang
 * @classname RunnerPool
 * @description [  ]
 * @date 2022/5/31 16:21
 */
public class RunnerPool {

    private RunningJobManager runningJobManager;

    private ThreadPoolExecutor executor;

    private RunnerFactory runnerFactory;

    public RunnerPool() {
        this.runningJobManager = new RunningJobManager();
        this.executor = initExecutor();
        this.runnerFactory = new RunnerFactory();
    }

    private ThreadPoolExecutor initExecutor() {
        return new ThreadPoolExecutor(4, 4, 30, TimeUnit.SECONDS,
                new SynchronousQueue<>(),
                new NameThreadFactory("JobRunnerPool"),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    public void executor(JobRunner runner,RunnerCallback callback) {
        this.executor.execute(new JobRunnerDelegate(runner,callback));
    }

    public class RunningJobManager {

    }

}